package org.javaboy.demo.dao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

@Repository
public class UserDao {
    @Autowired
    JdbcTemplate jdbcTemplate;

    public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }

    public void addMoney(String to, Double money) {
        jdbcTemplate.update("update user set money = money+? where username=?;", money, to);
    }

    public void minusMoney(String from, Double money) {
        jdbcTemplate.update("update user set money = money-? where username=?;", money, from);
    }
}
